package SpellCheck;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class utilClass {

	public static void main (String args[])
	{
		int counter = 0;
		int k = 97;
		int add =0 ;
		List<String> arrayofStringIndexes = new ArrayList<String>();
		while(counter<26)
		{
			int counter2 =0;
			int z=97;
			while(counter2 < 26)
			{
				char cd = (char)k;
				char dc = (char)z;
				counter2++;
				z++;
				String s = ""+cd+dc;
				arrayofStringIndexes.add(s);
				//System.out.println(s);
				add++;
			}k++;
			counter++;
		}
		//testforLength();
		
		testForFirstTwoCharsLength();
	}
	
	/**
	 * Reporting method :
	 * It tells the number of elements in each bucket , when using the implementaion approach 
	 */
	public static void testforLength()
	{
	
	TextReader txt = new TextReader();
	List<String> ghg = new ArrayList<String>();
	ghg = txt.ReadWordsFromFile("C:\\wordRoot.txt");
	
	Map<String,String> lenCal =  new HashMap<String,String>();
	
	System.out.println("length of seed"+ghg.size());
	
	int i =0 ;
	int len2compare = ghg.size();
	int seedlen =0;
	List<String> positionList = new ArrayList<String>();
	i=0;
	while(i< len2compare)
	{
		String var = ghg.get(i);
		
		if(seedlen < var.length())
		{
			seedlen = var.length();
			System.out.println("counter value is::"+i+" max len"+seedlen);
		}
		
		String str = Integer.toString(var.length());
		String jb = null;
	
		if(null != (jb = lenCal.get(str)))
		{
			Integer tk = Integer.valueOf(jb);
			int j = tk.intValue();
			j++;
			lenCal.put(str,String.valueOf(j));
		}
		else{
			lenCal.put(str, String.valueOf(1));
			positionList.add(str);
		}		
		i++;
		
	}	
	i=0;
	int l =0;
	while(i< lenCal.size())
	{
		System.out.println("val at this index position"+" :: " + i+ " key val is"+positionList.get(i)+ 
				"value is::"+lenCal.get(positionList.get(i)));
		Integer jk = Integer.valueOf(lenCal.get(positionList.get(i)));
		l = l+ jk.intValue();		
		i++;		
	}
	
	System.out.println("value of l "+l);
	
	System.out.println("value of "+len2compare);
	}
	
	public static void testForFirstTwoCharsLength()
	{
		TextReader txt = new TextReader();
		List<String> ghg = new ArrayList<String>();
		ghg = txt.ReadWordsFromFile("C:\\wordRoot.txt");
		
		Map<String,String> hm = new HashMap<String,String>();
		List<String> positionList = new ArrayList<String>();
		int lengthofRoot = ghg.size();
		int i=0;
		int k =0;
		while(i<lengthofRoot)
		{
			String var = ghg.get(i);
			if(var.length()>1)
			{
				String var2;
				if(null !=(var2 = hm.get(var.substring(0, 1))))
				{
					Integer it = Integer.valueOf(var2);
					k= it.intValue();
					k++;
					hm.put(var.substring(0, 1), String.valueOf(k));
				}
				else
				{
					hm.put(var.substring(0, 1), String.valueOf(1));
					positionList.add(var.substring(0, 1));
				}
				
			}
			i++;
		}
	}
}
